define(function(require, exports, module) {
    var ALL = require("../../common/all"),
        CONFIG = ALL.CONFIG,
        METHOD = ALL.METHOD,
        Init = ALL.Init;


    var _vm = Init.initVue({
        data : {
            id : null,
            name : "",
            check : {},
            res : {
                team_sn : "",
                no : "",
            }
        },
        methods: {
            submit : function() {
                var flag,
                    sn = '';

                this.check.$valid();
                flag = this.check.flag;

                if (!flag) { return; }

                sn = _vm.res.team_sn;

                if ( sn.length < 3) {
                    METHOD.alert("号段请输入3-6位纯数字");
                    return;
                }

                METHOD.loading.show();
                METHOD.ajax("team/agent/add",_vm.res,{type : 'post'}).done(function(){
                    METHOD.loading.hide();
                    METHOD.alert("操作成功").done(function(){
                        window.location.href = "../team/proxy.html";
                    });
                }).fail(function(){
                    METHOD.loading.hide();
                })
            },
            getInfoCallback : function(obj) {
                if (obj) {
                     if (obj.is_captain) {
                        METHOD.alert("设置的用户不能是团队长，请重新设置");
                        this.res.no = "";
                        return;
                    }
                    this.name = obj.name;
                } else {
                    this.name = "";
                }
            }
        }
    });

    _vm.id = METHOD.getQueryParms("id") || null;

    if (_vm.id) {
        METHOD.loading.show();
        METHOD.ajax("team/sn/detail",{team_id:_vm.id}).done(function(json){
            METHOD.loading.hide();
            _vm.res = json.data;
        }).fail(function(){
            METHOD.loading.hide();
        })
    }

});

